package com.ls.controller.area;

import com.ls.entity.ChinaArea;
import com.ls.service.IChinaAreaService;
import com.ls.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 区域相关接口
 * </p>
 *
 * @author pengyu
 * @since 2025-08-26
 */
@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    IChinaAreaService service;

    /**
     * 获取所有省份
     */
    @GetMapping(value = "provinces")
    public ResultData<ChinaArea> getProvinces() {
        return ResultData.successData(service.getProvinces());
    }

    /**
     * 根据省份ID获取城市列表
     */
    @GetMapping(value = "cities")
    public ResultData<ChinaArea> getCities(@RequestParam String provinceId) {
        return ResultData.successData(service.getCitiesByProvinceId(provinceId));
    }

    /**
     * 根据城市ID获取区县列表
     */
    @GetMapping(value = "districts")
    public ResultData<ChinaArea> getDistricts(@RequestParam String cityId) {
        return ResultData.successData(service.getDistrictsByCityId(cityId));
    }
}